package com.itheima.sfbx.file.demo;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.PartETag;
import com.aliyun.oss.model.UploadPartRequest;
import com.aliyun.oss.model.UploadPartResult;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * TODO
 *
 * @Author whx
 * @Date 2025/1/6 15:17
 */
public class MyThread extends Thread{


    private OSS ossClient;

    private UploadPartRequest uploadPartRequest;

    private List<PartETag> partETags;

    private int i;

    private CountDownLatch countDownLatch;

    public MyThread(OSS ossClient, UploadPartRequest uploadPartRequest, List<PartETag> partETags, int i, CountDownLatch countDownLatch){
        this.ossClient = ossClient;
        this.uploadPartRequest = uploadPartRequest;
        this.partETags = partETags;
        this.i = i;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
        // 每次上传分片之后，OSS的返回结果包含PartETag。PartETag将被保存在partETags中。
        System.out.println("开始上传"+(i+1));
        partETags.add(uploadPartResult.getPartETag());
        System.out.println("上传结束"+(i+1));
        countDownLatch.countDown();
    }
}
